package StudentSystem;
import java.util.*;
public class StudentXZ {
	public static void main(String[] args) {
		InformationSystem stm= new InformationSystem();
		InformationScanSystem datascan =new InformationScanSystem();
		ExitSystem EX=new ExitSystem();
        //数据初始化
		stm.rens=datascan.Scan(stm.teacher,stm.coursesT,stm.student ,stm.coursesS,stm.Sdata,stm.Tdata);
		//Sdata:{{{学生数}},{学生编号，学生密码，学生姓名，学生性别，{课程编号}，{课程名称}，{课程时间}，{课程地点}}}
		//Tdata:{{{教师数}},{教师编号，教师密码，教师姓名，教师性别，{课程编号}，{课程名称}，{课程时间}，{课程地点}}}
		while(stm.messagepd==1){
			new Home();
			while(stm.exit==0){
					new  AdministrationSystem();
					new PersonalSystem();
					new InformationFindSystem();
					EX.ExitSystem1();
				}
			new ExitSystem();
		}

}
}
	class  InformationSystem{

		static  SystemModule teacher=new SystemModule(),student=new SystemModule();
		static  Course coursesT=new Course(),coursesS=new Course();
		static  Scanner sr = new Scanner(System.in);

		public static int  Administratorzh=123456,Administratorpd=1000;//管理员账户，密码=1000   初始学生账户，密码=0000
		public static int[] rens =new int[2];///人数
		public static int messagepd=1,shu1,shu2,jxsbjxt=0,dkxz=-1;//老师课程数，学生课程数,进入教师(1)/学生(2)编辑系统,端口选择      0管理员端   1学生端
		public static String[][][] Sdata={{{"1"}},{{"202209001"},{"12345"},{"王喆"},{"男"},{"001"},{"python"},{"8:00-12:00"},{"教学楼105"}}},
				Tdata={{{"1"}},{{"1202209001"},{"12345"},{"吴刚"},{"男"},{"001"},{"python"},{"8:00-12:00"},{"教学楼105"}}};
		public static int input1=-1,exit=0,lrenshuT,lrenshuS;//     lrenshuT录入教师人数lrenshuS录入学生人数



	}

class Home extends InformationSystem {
	public Home(){
	while(dkxz!=0&&dkxz!=1&&dkxz!=2&&dkxz!=101) {


		System.out.println("  0：管理信息录入系统\n  1: 个人信息系统\n  2：信息查询系统\n  101：退出程序系统\n 请输入序号>>");
		dkxz = sr.nextInt();
		sr.nextLine();

	}}
}
class AdministrationSystem extends InformationSystem{
	public  AdministrationSystem(){
		if(dkxz==0){
			System.out.println("<<<管理信息录入系统>>>\n请输入账号>>");
			input1=sr.nextInt();
			if (input1==Administratorzh){
				System.out.println("<<<管理员信息录入系统>>>\n输入密码>>");
				input1=sr.nextInt();
				if(input1==Administratorpd) {
					System.out.println("输入：\n1	为进入<<<教师信息录入系统>>>\n2	为进入<<<学生信息录入系统>>>>\n请输入>>");
					input1=sr.nextInt();
					while(input1 == 1) {
						System.out.println("<<<教师信息录入系统>>>");
						System.out.println("请输入录入教师人数（1000以内）>>");
						lrenshuT = sr.nextInt();
						for (int j = rens[1]; j < lrenshuT+rens[1]; j++) {

							System.out.println("请输入教师10位数编码>>");
							teacher.user[j] = sr.nextInt();
							System.out.println("请输入教师名字>>");
							teacher.name[j] = sr.nextLine();
							System.out.println("请输入教师性别>>");
							teacher.sex[j] = sr.nextLine();

							System.out.println("请输入教师所教课程个数(100以内)>>");
							shu1= sr.nextInt();
							for(int i=0;i<shu1;i++){

								System.out.println("请输入教师所教课程编号>>");
								coursesT.number[j][i]=sr.nextInt();
								System.out.println("请输入教师所教课程名字>>");
								coursesT.name[j][i] = sr.nextLine();
								System.out.println("请输入教师所教课程时间>>");
								coursesT.time[j][i]=sr.nextLine();
								System.out.println("请输入教师所教课程地点>>");
								coursesT.sit[j][i]=sr.nextLine();
							}

						}
						break;
					}
					while(jxsbjxt==2){
						System.out.println("<<<进入学生信息录入系统>>>");
						System.out.println("请输入添加学生人数>>");
						lrenshuS=sr.nextInt();
						for(int j=rens[0];j<lrenshuS+rens[0];j++){

							System.out.println("请输入学生9位数编码>>");
							student.user[j]=sr.nextInt();


							System.out.println("请输入学生名字>>");
							student.name[j]=sr.nextLine();


							System.out.println("请输入学生性别>>");////有问题这里
							student.sex[j]=sr.nextLine();

							System.out.println("请输入学生所选课程个数(100以内)>>");
							shu2= sr.nextInt();
							for(int i=0;i<shu2;i++){

								System.out.println("请输入学生所教课程编号>>");
								coursesS.number[j][i]=sr.nextInt();
								System.out.println("请输入学生所选课程名字>>");
								coursesS.name[j][i] = sr.nextLine();
								System.out.println("请输入学生所选课程时间>>");
								coursesS.time[j][i]=sr.nextLine();
								System.out.println("请输入学生所选课程地点>>");
								coursesS.sit[j][i]=sr.nextLine();
							}

						}
						break;
					}
			}
		}
	}
	}
}
class PersonalSystem extends InformationSystem {
	public PersonalSystem(){
		if(dkxz==1){
			int wz = 0;
			System.out.println("<<<个人信息系统>>>\n请输入账号>>");
			String user0;
			;//
			int stpd0 = -1, zh0 = 0, i = 0;
			user0 = sr.nextLine();
			zh0 = Integer.parseInt(user0);
			while (stpd0 == -1) {
				if (user0.length() == 9) {
					zh0 = Integer.parseInt(user0);
					for (i = 0; i < student.name.length; i++)
						if (student.user[i] == zh0) {
							stpd0 = 0;
							wz = i;
							System.out.println("输入密码>>");
							String pass1;
							pass1 = sr.nextLine();
							while (!student.password[wz].equals(pass1)) {
								System.out.println("密码错误，请重新输入密码>>");
								pass1 = sr.nextLine();
							}
							break;
						}

				} else if (user0.length() == 10) {
					zh0 = Integer.parseInt(user0);
					for (i = 0; i < teacher.name.length; i++)
						if (teacher.user[i] == zh0) {
							stpd0 = 1;
							wz = i;
							System.out.println("输入密码>>");
							String pass1;
							pass1 = sr.nextLine();
							while (!teacher.password[wz].equals(pass1)) {
								System.out.println("密码错误，请重新输入密码>>");
								pass1 = sr.nextLine();
							}
							break;
						}

				} else {
					System.out.print("！！账号不存在！！");
					System.out.println("是否退出查询系统，输入102退出;或者重新输入");
					input1 = sr.nextInt();
					if (input1 == 102) stpd0 = -2;
				}

			}
			System.out.println("进入信息编辑系统");

			int wzl = 0, bh, pd4 = -1, tc = 1, pd2 = 0;//课程位置，需修改课程编号，判断是否修改  退出循环
			while (stpd0 == 0) {
				System.out.println("<<<学生信息编辑系统>>>");
				System.out.println("是否查看个人信息（查看输入1）");
				pd2 = sr.nextInt();
				if (pd2 == 1) {
					System.out.println("学生选课");
					System.out.println("学生相关信息");
					System.out.println("学号：" + student.user[wz]);
					System.out.println("学生名字：" + student.name[wz]);
					System.out.println("学生性别：" + student.sex[wz]);
					System.out.println("课程号                           " + "课程名字                     " + "课程时间                              " + "课程地点");

					for (i = 0; i < coursesS.time[wz].length; i++) {
						if (coursesS.time[wz][i] != null)
							System.out.println("         " + coursesS.number[wz][i] + "          " + coursesS.name[wz][i] + "         " + coursesS.time[wz][i] + "          " + coursesS.sit[wz][i]);
					}
				}
				input1=0;
						System.out.println("是否修改学生个人信息（输入1进入）");
				input1=sr.nextInt();
						if(input1==1)

				{
					System.out.println("学生学号：");
					student.user[wz] = sr.nextInt();
					sr.nextLine();
					System.out.println("学生名字");
					student.name[wz] = sr.nextLine();
					System.out.println("学生性别");
					student.sex[wz] = sr.nextLine();
				}
				System.out.println("是否修改学生选课信息（输入1进入）");
				input1=sr.nextInt();
				while(tc==input1)
				{
					System.out.println("请输入学生要修改或者查询的课程编号");
					bh = sr.nextInt();
					int j;
					j = 1;
					while (j == 1) {
						for (i = 0; i < coursesS.time[wz].length; i++)//i是学生查询对应课程位置
						{
							if (coursesS.number[wz][i] == bh) {
								wzl = i;
								j = 0;
								break;
							}
						}
						if (j == 1) {
							System.out.println("未查询到该课程！！\n请重新输入,要修改或者查询的课程编号");
							bh = sr.nextInt();
						}
					}
					if (coursesS.number[wz][i] == bh) {
						System.out.println("课程号                           " + "课程名字                     " + "课程时间                              " + "课程地点");
						System.out.println("          " + coursesS.number[wz][i] + "          " + coursesS.name[wz][i] + "          " + coursesS.time[wz][i] + "          " + coursesS.sit[wz][i]);

						////////////////////////////////////可调  共用course信息
						System.out.println("请输入学生要退/删课程(输入1改课，输入0退课,其他退出)");
						pd4 = sr.nextInt();
						if (pd4 == 1) {
							System.out.println("请输入学生要选课程编号");
							bh = sr.nextInt();
							for (i = 0; i < coursesS.time[wz].length; i++) {
								if (coursesT.number[wz][i] == bh) {
									wzl = i;
									break;
								}
							}
							System.out.println("请输入学生所选课程编号");
							coursesS.number[wz][wzl] = sr.nextInt();
							sr.nextLine();
							System.out.println("请输入学生所选课程名字");
							coursesS.name[wz][wzl] = sr.nextLine();
							System.out.println("请输入学生所选课程时间");
							coursesS.time[wz][wzl] = sr.nextLine();
							System.out.println("请输入学生所选课程地点");
							coursesS.sit[wz][wzl] = sr.nextLine();

						} else if (pd4 == 0) {
							coursesS.number[wz][wzl] = -1;
							coursesS.name[wz][wzl] = "无";
							coursesS.time[wz][wzl] = "无";
							coursesS.sit[wz][wzl] = "无";
						}
						System.out.println("是否完成课程信息修改(输入2退出)");
						pd4 = sr.nextInt();
						if (pd4 == 2) break;
					} else {
						System.out.println("输入学生要查询课程编号不存在或者错误！！\n若退出请输入输入1（重新输入请输入其他数）>>");
						input1 = sr.nextInt();
						if (input1 == 1) {
							break;
						}
					}
				}
				System.out.println("退出信息查询系统请输入1（重新输入请输入其他数）>>");
				input1=sr.nextInt();
				if(input1==1)
				{
					break;
				}
			}
			//教师信息查询
			while (stpd0 == 1) {
				System.out.println("<<<教师信息编辑系统>>>");

				System.out.println("是否查看个人信息（查看输入1）");
				pd2 = sr.nextInt();
				if (pd2 == 1) {
					System.out.println("教师所教课");
					System.out.println("教师相关信息");
					System.out.println("教师号：" + teacher.user[wz]);
					System.out.println("教师名字：" + teacher.name[wz]);
					System.out.println("教师性别：" + teacher.sex[wz]);
					System.out.println("课程号                           " + "课程名字                     " + "课程时间                              " + "课程地点");

					for (i = 0; i < coursesT.time[wz].length; i++) {
						if (coursesT.time[wz][i] != null)
							System.out.println("       " + coursesT.number[wz][i] + "              " + coursesT.name[wz][i] + "               " + coursesT.time[wz][i] + "                  " + coursesT.sit[wz][i]);
					}
				}
				System.out.println("是否修改个人信息（输入1为修改）");
				input1 = sr.nextInt();
				if (input1 == 1) {
					System.out.println("请输入教师要修改的课程编号");
					bh = sr.nextInt();
					int j = 1;
					while (j == 1) {
						for (i = 0; i < coursesT.time[wz].length; i++)//wzl是教师查询对应课程位置
						{
							if (coursesS.number[wz][i] == bh) {
								wzl = i;
								j = 0;
								break;
							}
						}
						if (j == 1) {
							System.out.println("未查询到该课程！！\n请重新输入,要修改或者查询的课程编号");
							bh = sr.nextInt();
						}
					}
					System.out.println("请输入教师10位数编码>>");
					teacher.user[wz] = sr.nextInt();
					sr.nextLine();
					System.out.println("请输入教师名字>>");
					teacher.name[wz] = sr.nextLine();
					System.out.println("请输入教师性别>>");
					teacher.sex[wz] = sr.nextLine();

					System.out.println("是否修改课程信息（输入0:修改 1:删除））>>");
					input1 = sr.nextInt();
					if (input1 == 0) {
						System.out.println("请输入教师所教课程编号>>");
						coursesT.number[wz][wzl] = sr.nextInt();
						sr.nextLine();
						System.out.println("请输入教师所教课程名字>>");
						coursesT.name[wz][wzl] = sr.nextLine();
						System.out.println("请输入教师所教课程时间>>");
						coursesT.time[wz][wzl] = sr.nextLine();
						System.out.println("请输入教师所教课程地点>>");
						coursesT.sit[wz][wzl] = sr.nextLine();
					} else if (input1 == 0) {
						coursesT.number[wz][wzl] = -1;
						coursesT.name[wz][wzl] = "无";
						coursesT.time[wz][wzl] = "无";
						coursesT.sit[wz][wzl] = "无";
					}
					System.out.println("退出信息查询系统请输入1（重新输入,请输入其他数）>>");
					input1 = sr.nextInt();

					if (input1 == 1) {
						break;
					}

				}

			}
		}
}}

class InformationFindSystem extends InformationSystem{
	public InformationFindSystem(){
		String user;//
		int stpd1=-1,zh,i=0,wz=0;
		if (dkxz==2){
			System.out.println("<<<信息查询系统>>>");
			System.out.println("请输入个人数字账号>>");
			user=sr.nextLine();
			zh=Integer.parseInt(user);
			while(stpd1==-1){

				if(user.length()==9)
				{
					zh=Integer.parseInt(user);
					for(i=0;i<student.name.length;i++)
						if(student.user[i]==zh)
						{
							stpd1=0;
							wz=i;
							System.out.println("输入密码>>");
							String pass1;
							pass1=sr.nextLine();
							while(!student.password[wz].equals(pass1)){
								System.out.println("密码错误，请重新输入密码>>");
								pass1=sr.nextLine();
							}
							break;
						}

				}
				else if(user.length()==10)
				{
					zh=Integer.parseInt(user);
					for(i=0;i<teacher.name.length;i++)
						if(teacher.user[i]==zh)
						{
							stpd1=1;
							wz=i;
							System.out.println("输入密码>>");
							String pass1;
							pass1=sr.nextLine();
							while(teacher.password[wz].equals(pass1)){
								System.out.println("密码错误，请重新输入密码>>");
								pass1=sr.nextLine();
							}
							break;
						}
				}

				else {
					System.out.print("！！账号不存在！！");
					System.out.println("是否退出查询系统，输入102退出;或者重新输入");
					input1=sr.nextInt();
					sr.nextLine();
					if(input1==102) stpd1=-2;
				}

			}


			while(stpd1==0){
				if(student.name.length>0){
					System.out.println("学生选课");
					System.out.println("学生相关信息");
					System.out.println("学号： "+student.user[wz]);
					System.out.println("学生名字： "+student.name[wz]);
					System.out.println("学生性别： "+student.sex[wz]);
					System.out.println("课程号                           "+"课程名字                     "+"课程时间                              "+"课程地点");
					for(i=0;i<coursesS.time[wz].length;i++){
						if(coursesS.time[wz][i]!=null)
							System.out.println("       "+coursesS.number[wz][i]+"    "+coursesS.name[wz][i]+"   "+coursesS.time[wz][i]+"    "+coursesS.sit[wz][i]);
					}
				}
				break;
			}
			while(stpd1==1){

				if(teacher.name.length>0){
					System.out.println("教师所教课");
					System.out.println("教师相关信息");
					System.out.println("教师号："+teacher.user[wz]);
					System.out.println("教师名字："+teacher.name[wz]);
					System.out.println("教师性别："+teacher.sex[wz]);
					System.out.println("课程号                                  "+"课程名字                                    "+"课程时间                                   "+"课程地点");
					for(i=0;i<coursesT.time[wz].length;i++){
						if(coursesT.time[wz][i]!=null)
							System.out.println("           "+coursesT.number[wz][i]+"           "+coursesT.name[wz][i]+"           "+coursesT.time[wz][i]+"           "+coursesT.sit[wz][i]);
					}

				}
				break;
			}
		}}
}

class ExitSystem extends InformationSystem{
	public ExitSystem(){
            if(dkxz==101){
				int tc=0;
				System.out.println("<<<程序退出系统>>>");
				System.out.print("是否退出系统，输入1退出>>");
				tc=sr.nextInt();
				if(tc==1) System.exit(0);
				else exit=0;
	}}
	public void ExitSystem1(){
		System.out.println("是否返回首页，输入103返回首页");
		input1=sr.nextInt();
		sr.nextLine();
		if(input1==103){exit=1;dkxz=-1;System.out.println("  <<<首页>>>\n ");}
		}
	}